package com.yulinlin.websocket.server.controller;

import com.yulinlin.common.anno.JwtElement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "配置")
@RequestMapping("config")
@RestController
public class ConfigController {

    @Autowired
    DiscoveryClient discoveryClient;

    private String serverId="websocket-node";


    @ApiOperation("服务列表")
    @JwtElement
    @RequestMapping(value = "serverList",method = {
            RequestMethod.POST,
            RequestMethod.GET,
    })
    public List<String> serverList(){
        return discoveryClient.getInstances(serverId).stream().map(row -> {
            return row.getUri().toString();
        }).collect(Collectors.toList());

    }


}
